package com.javaAPI.demo4;

import java.util.Scanner;

public class LoginDemo {
    public static void main(String[] args) {

        //正确用户账号和密码
        String userName = "admin";
        String passWord = "123456";
        //账号是错次数
        int pwdCount = 3;
        for (int i = 0; i < pwdCount; i++) {
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入用户名称:");
            String user = scanner.nextLine();
            System.out.println("请输入用户密码:");
            String pwd = scanner.nextLine();
            //账号密码正确
            if (userName.equals(user) && passWord.equals(pwd)) {
                System.out.println("登录成功");
                break;
            } else {
                if (i == pwdCount - 1) {
                    System.out.println("账户已冻结，请明天再试");
                    return;
                }

                System.out.println("账户或密码错误,剩余" + (pwdCount - i - 1) + "次");
            }
        }
    }
}
